package com.neusoft.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neusoft.dto.DeptAddDto;
import com.neusoft.dto.DeptCondition;
import com.neusoft.service.DeptService;
import com.neusoft.utils.ResponseCode;
import com.neusoft.utils.ServerResponse;
import com.neusoft.vo.DeptBaseVo;
import com.neusoft.vo.DeptEmpFinVo;
import com.neusoft.vo.DeptListVo;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController()
@RequestMapping("/api")
@Api(tags = "部门管理")
public class DeptController {
    @Resource
    private DeptService deptService;
//    //查询所有部门信息,分页
//    @RequestMapping(value = "/list",method = RequestMethod.GET)
//    public ServerResponse<IPage<DeptListVo>> getDeptList(Integer pageNum, Integer pageSize) {
//        return ServerResponse.success(deptService.getDeptList(pageNum,pageSize));
//    }
    /*根据名称和状态进行条件查询*/
    @RequestMapping(value = "/selectDept",method = RequestMethod.PUT)
    public ServerResponse<IPage<DeptListVo>> getDeptList(@RequestBody DeptCondition deptCondition,@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
        return ServerResponse.success(deptService.getDeptCondition(deptCondition,pageNum,pageSize));
    }
    //根据id查询部门信息
    @RequestMapping(value = "/getOneDept",method = RequestMethod.GET)
    public ServerResponse<DeptBaseVo> getDeptById( Integer id) {
        return ServerResponse.success(deptService.getDeptById(id));
    }
    //根据id查询部门成员信息
    @RequestMapping(value = "/getOneMemberDept",method = RequestMethod.GET)
    public ServerResponse<List<DeptEmpFinVo>> getDeptEmpById(Integer id) {
        return ServerResponse.success(deptService.getDeptEmpById(id));
    }
    //更新状态
    @RequestMapping(value = "/updateStatusDept",method = RequestMethod.PUT)
    public ResponseCode updateDeptStatus(Integer id) {
        return deptService.updateDeptStatus(id);
    }
    //新增部门
    @RequestMapping(value = "/addDept",method = RequestMethod.POST)
    public ServerResponse<?> addDept(@RequestBody DeptAddDto dept) {
        return deptService.addDept(dept);
    }
    //修改部门信息
    @RequestMapping(value = "/modifyDept",method = RequestMethod.PUT)
    public ServerResponse<?> updateDept( Integer id,@RequestBody DeptAddDto dept) {
        return deptService.updateDept(id,dept);
    }

}
